import MobileDetect from 'mobile-detect';
function getSystem() {
  Array.prototype.contains = function (needle) {
    for (i in this) {
      if (this[i].indexOf(needle) > 0) return i;
    }
    return -1;
  };

  var device_type = navigator.userAgent; //获取userAgent信息
  console.log(device_type);
  var md = new MobileDetect(device_type); //初始化mobile-detect
  var os = md.os(); //获取系统
  var mob = md.mobile();
  var phone = md.phone();
  var version = md.version();
  var tablet = md.tablet();
  // alert(os+'---'+mob+'~~~'+phone+'||'+tablet+'----'+version)
  // alert(md.is('phone')) //返回布尔
  // alert(md.is('tablet'))
  // alert(md.is('HTC')); //是不是HTC的牌子
  // alert(md.mobile('tablet')); //返回品牌
  // alert(md.mobile('phone'));
  var model = '';
  if (os == 'iOS') {
    //ios系统的处理
    os = +md.version('iPhone');
    console.log(os);
    model = md.mobile();
  } else if (os == 'AndroidOS') {
    //Android系统的处理
    os = md.os() + md.version('Android');
    var sss = device_type.split(';');
    var i = sss.contains('Build/');
    if (i > -1) {
      debugger;
      model = sss[i].substring(0, sss[i].indexOf('Build/'));
    }
  }
  //    alert(os + "---" + model);//打印系统版本和手机型号
  //   document.write(model + '||' + os, '打印系统版本和手机型号')
  return { md, os, model, mob, phone };
}

export const { md, os, model, phone, mob } = getSystem();
